package com.wlys.player.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wlys.player.R;
import com.wlys.player.model.Track;

public class TrackAdapter extends BaseCacheListAdapter<Track>
{

    public TrackAdapter(Context context)
    {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder;
        if (null == convertView)
        {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_track, null);
            viewHolder.trackName = (TextView) convertView
                    .findViewById(R.id.track_name);
            viewHolder.trackArtist = (TextView) convertView
                    .findViewById(R.id.track_artist);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        
        Track track = getItem(position);
        viewHolder.trackName.setText(track.getName());
        viewHolder.trackArtist.setText(track.getArtist().getName());

        return convertView;
    }

    private class ViewHolder
    {
        TextView trackName;
        TextView trackArtist;
    }

}
